package design_pattern.inversion;

/**
 * @Name : inversion.DependencyInversion2
 * @Description : 描述
 * Created by cyd on 2020-12-14 09:25:08
 */
public class DependencyInversion2 {
    public static void main(String[] args) {
        Person2 person2 = new Person2();

        person2.receive(new Email2());
        person2.receive(new WeChat());
    }
}

//实现功能的接口
interface IReceive {
    void doReceive();
}

//Person2类依赖于IReceive接口执行receive（）方法
class Person2 {
    public void receive(IReceive iReceive) {
        iReceive.doReceive();
    }
}

//Email2实现IReceive接口，覆写接口里的doReceive（）方法，具体实现功能
class Email2 implements IReceive {
    @Override
    public void doReceive() {
        System.out.println("email:hello");
    }
}

class WeChat implements IReceive {
    @Override
    public void doReceive() {
        System.out.println("wechat:hello");
    }
}
